<template>
	<view>
		<evan-switch v-model="checked" @change="Onchange"></evan-switch>
		<text>{{checked?"已收藏":"未收藏"}}</text>
	</view>
</template>

<script>
	import evanSwitch from '../../common/evan-switch/evan-switch.vue';
	import {setCollect,getCollect,removeCollect} from '../../utils/stroage.js'
	export default{
		props:["bdid"],
		components:{
			evanSwitch
		},
		data(){
			return {
				checked:false
			}
		},
		methods:{
			Onchange(){
				console.log(this.checked)
				if(this.checked){
					setCollect(this.bdid)
					uni.showToast({
						icon: 'success',
						title: '已收藏'
					})
				}else{
					console.log(23456)
					removeCollect(this.bdid)
					uni.showToast({
						icon: 'success',
						title: '已取消收藏'
					})
				}
			}
		},
		watch:{
			bdid:function(newVal,oldVal){
				let coll=getCollect()
				console.log(coll)
				this.checked=coll.indexOf(newVal)>-1
				console.log(coll.indexOf(newVal))
			}
		}
	}
</script>

<style>
</style>
